package com.example.demo.services.imp;


import com.alipay.api.domain.Article;
import com.example.demo.entity.*;
import com.example.demo.mapper.ContentShowMapper;
import com.example.demo.services.ArticleSecService;
import com.example.demo.services.ContentShowService;
import com.example.demo.services.articleService;
import com.example.demo.services.test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class ContentShowServiceImp implements ContentShowService {

    @Autowired
    private ContentShowMapper contentShowMapper;


    @Autowired
    private ArticleSecService articlesService;



    @Autowired
    private articleService articleService;


    @Override
    public List<ContentShow> selectAll() {
        return contentShowMapper.selectAll();
    }

    @Override
    public List<wenzhang> getWenzhangList(Integer pid) {
        List<ArticleSec> chirldrenList =articlesService.selectPinglunId(pid);
        List<ContentShow> content=contentShowMapper.selectAll();




        return null;
    }

    /**
     * 返回树形结构数据   封装成一个对象
     * @param pid 文章id
     * @return
     */
    @Override
    public wenzhang getWenzhang(Integer pid) {
        ContentShow contentShow = contentShowMapper.selectarticleId(pid);
        List<ArticleSec> chirldrenList = articlesService.selectPinglunId(pid);
        article duixiang=articleService.selectId(pid);
        //实例化
        wenzhang test = new wenzhang();
        test.setName(duixiang.getUserName());
        test.setTitle(duixiang.getTitle());
        test.setCreated(duixiang.getDateTime());
        test.setSec(contentShow.getSec());
        List<Chirldren> list=new ArrayList<>();
        for (ArticleSec articleSec:chirldrenList) {
            if(articleSec.getArticleId()==contentShow.getArticleId()) {
                Chirldren chirldren=new Chirldren();
                replayContent replaycontent=new replayContent();
                chirldren.setArticleId(articleSec.getArticleId());
                chirldren.setCreateTime(articleSec.getCreateTime());
                chirldren.setId(articleSec.getId());
                chirldren.setName(articleSec.getName());
                chirldren.setPinglunId(articleSec.getPinglunId());
                chirldren.setSec(articleSec.getSec());
                chirldren.setUserId(articleSec.getUserId());
                chirldren.setUserName(articleSec.getUserName());
                chirldren.setUserSec(articleSec.getUserSec());
                chirldren.setInputShow(false);
                replaycontent.setComment(articleSec.getUserSec());
                replaycontent.setFrom(articleSec.getUserName());
                //老师回复评论所以是fromid
                replaycontent.setFromId(articleSec.getUserId());
                replaycontent.setInputShow(false);
                replaycontent.setToId(articleSec.getPinglunId());
                replaycontent.setTo(articleSec.getName());
                replaycontent.setTime(articleSec.getCreateTime());
                List<replayContent> hello = new ArrayList<>();
                hello.add(replaycontent);
                chirldren.setReplayContentList(hello);
                list.add(chirldren);
            }
        }
        test.setChildren(list);
        return test;
    }
}
